package org.libl.service.student.impl;

import org.libl.dao.student.StudentDao;
import org.libl.dao.student.impl.StudentDaoImpl;
import org.libl.domain.PageBean;
import org.libl.domain.Student;
import org.libl.service.student.StudentService;

import java.util.List;

public class StudentServiceImpl implements StudentService {
    //1.创建dao对象
    private StudentDao dao = new StudentDaoImpl();

    public List<Student> findAll(){
        return dao.selectAll();
    }

    public PageBean<Student> findPageByCurrentPage(Integer currentPage, Integer pageSize){
        //1.创建PageBean对象,封装分页数据
        PageBean<Student> pageBean = new PageBean<Student>();
        //2.封装当前页码数字
        pageBean.setCurrentPage(currentPage);
        //3.封装每页显示的具体条数
        pageBean.setPageSize(pageSize);
        //4.封装每页显示的具体数据
        List<Student> list = dao.findByPage(currentPage, pageSize);
        pageBean.setList(list);
        //5.封装总的条数
        Number number= dao.findTotalCount();
        int totalCount =number.intValue();
        pageBean.setTotalCount(totalCount);
        //6.封装总的页码数: 总的条数101  每页显示10条
        Integer totalPage  = (totalCount%pageSize==0)?
                                    totalCount/pageSize : ((totalCount/pageSize)+1);
        pageBean.setTotalPage(totalPage);
        return pageBean;
    }
}
















